package cluster

import (
	"github.com/go-playground/validator/v10"
	"github.com/rs/xid"
	"time"
)

const (
	AppName = "cluster"
)

var (
	validate = validator.New()
)

func NewCreateClusterRequest() *CreateClusterRequest {
	return &CreateClusterRequest{}
}

func NewClusterInfo(req *CreateClusterRequest) (*ClusterInfo, error) {
	return &ClusterInfo{
		Id:       xid.New().String(),
		CreateAt: time.Now().UnixMilli(),
		Node:     &NodeInfo{},
	}, nil
}

func NewDefaultInfo() *ClusterInfo {
	return &ClusterInfo{
		Node: &NodeInfo{},
	}
}

// 参数校验
func (req *CreateClusterRequest) Validate() error {
	return validate.Struct(req)
}

func NewCluseterSet() *ClusterSet {
	return &ClusterSet{
		Items: []*ClusterInfo{},
	}
}

func (s *ClusterSet) Add(item any) {
	s.Items = append(s.Items, item.(*ClusterInfo))
}
